package com.lune.job.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lune.job.mapper.FavorMapper;
import com.lune.job.pojo.Favor;
import com.lune.job.pojo.ResPageBean;
import com.lune.job.service.ICompanyService;
import com.lune.job.service.IFavorService;
import com.lune.job.service.IPostService;
import com.lune.job.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Caiyilin
 * @since 2022-03-06
 */
@Service
public class FavorServiceImpl extends ServiceImpl<FavorMapper, Favor> implements IFavorService {

    @Autowired
    private FavorMapper favorMapper;

    @Autowired
    private IStudentService studentService;
    @Autowired
    private ICompanyService companyService;
    @Autowired
    private IPostService postService;

    /**
     * 分页查询职位收藏
     *
     * @param currentPage
     * @param size
     * @param favor
     * @return
     */
    @Override
    public  IPage<Favor> queryPage(Integer currentPage, Integer size, Favor favor) {
        Page<Favor> page = new Page<>(currentPage, size);
        IPage<Favor> favorIPage = favorMapper.queryPage(page, favor);
        return favorIPage;
    }

    /**
     * 条件查询职位收藏
     *
     * @param favor
     * @return
     */
    @Override
    public List<Favor> queryByCon(Favor favor) {
        List<Favor> favors = favorMapper.queryByCon(favor);
        favors.forEach(item->{
            item.setCompany(companyService.getById(item.getCompany_id()));
            item.setStudent(studentService.getById(item.getStudent_id()));
            item.setPost(postService.getById(item.getPost_id()));
        });
        return favors;
    }
}
